package reduce.fz.com.reduce.activity;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import reduce.fz.com.reduce.R;
import reduce.fz.com.reduce.constant.PublishParams;
import reduce.fz.com.reduce.custom.TabIndicator;
import reduce.fz.com.reduce.display.Display;
import reduce.fz.com.reduce.display.MainDisplay;
import reduce.fz.com.reduce.photo.PhotoWallActivity;

public class TeamWitnessActivity extends BaseToolBarActivity {
    private TabIndicator tabIndicator;
    private Display display = new MainDisplay(this, R.id.main_container);
    //发布见证按钮
    private TextView mPubButton;
    //发布照片最多氪选择六张图片
    private int MAX_IMAGE_COUNT = 6;
    //本地
    ArrayList<String> mPaths = new ArrayList<String>();
    private final static int SELECT_PIC = 123;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_team_witness);
        initTabIndicatior();


    }

    /**
     * toobar上添加切换tab选项(见证-动态)
     */
    public void initTabIndicatior() {
        View view = LayoutInflater.from(this).inflate(R.layout.view_tab_toobar, mToolbar, false);
        initPubButton(view);
        this.tabIndicator = (TabIndicator) view.findViewById(R.id.tab_toolbar);
        tabIndicator.setVisibility(View.VISIBLE);
        int x = getResources().getDimensionPixelSize(R.dimen.dimen_60);
        tabIndicator.setTabMarginX(x, x);
        List<String> title = new ArrayList<String>();
        title.add("见证");
        title.add("动态");
        tabIndicator.setTitleList(title);
        initTabIndicatiorListener();
        mToolbar.addView(view);
    }

    /**
     * 初始化发布按钮
     * @param view
     */
    public void initPubButton(View view) {
        mPubButton = (TextView) view.findViewById(R.id.toolbar_next_button);
        mPubButton.setVisibility(View.VISIBLE);
        mPubButton.setText("发布");
        mPubButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectPhoto();

            }
        });
    }

    /**
     * 选择照片操作
     */
    private void selectPhoto() {
        Intent intent = new Intent(this, PhotoWallActivity.class);
        intent.putExtra(PublishParams.MAX_SELECT_COUNT, MAX_IMAGE_COUNT);
        intent.putExtra(PublishParams.NEXT_ACTIVITY_WITH_RESULT, PubWitnessActivity.class.getName());
        startActivity(intent);
    }

    public void initTabIndicatiorListener() {
        this.tabIndicator.setOnTabSelectedListener(new TabIndicator.OnTabSelectedListener() {
            @Override
            public void onTabReselected(int position) {

            }

            @Override
            public void onTabSelected(int position) {
                switch (position) {
                    case 0:
                        showWitnessFragment(null);
                        break;
                    case 1:
                        showDynamicFragment(null);

                }

            }
        });
    }

    public void showWitnessFragment(Long teamid) {
        display.showWitnessFragment(teamid);

    }


    public void showDynamicFragment(Long teamid) {
        display.showWitnessDynamic(teamid);
    }

    @Override
    public void initWidget() {

    }

    @Override
    public void initListener() {
    }
}
